package com.example.ruiji.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.ruiji.common.Result;
import com.example.ruiji.entity.Employee;
import com.example.ruiji.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/login")
    public Result<Employee> login(@RequestBody Employee employee) {
        return employeeService.login(employee);
    }

    @PostMapping("/logout")
    public Result<String> logout() {
        return employeeService.logout();
    }

    @PostMapping
    public Result<String> addEmployee(@RequestBody Employee employee) {
        return employeeService.addEmployee(employee);
    }

    @GetMapping("/page")
    public Result<Page<Employee>> pageResult(Integer page, Integer pageSize, String name) {
        return employeeService.Page(page, pageSize, name);
    }

    @PutMapping
    public Result<String> updateEmployee(@RequestBody Employee employee) {
        return employeeService.updateEmployee(employee);
    }

    @GetMapping("/{id}")
    public Result<Employee> getById(@PathVariable Long id) {
        return employeeService.getById(id);
    }

}
